package com.suixun.controller.handle;

import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * 功能描述: 异常拦截器
 * 
 * @author jacky
 * @date 2018年1月5日下午7:12:22
 */
@ControllerAdvice
public class ExceptionHandle {

	private final static Logger logger = Logger.getLogger(ExceptionHandle.class);

	@Value("${error.path}")
	private String errorView;
	
    @ExceptionHandler(value = Exception.class)
    public ModelAndView defaultErrorHandler(Exception e, HttpServletRequest request) throws Exception {
        logger.info("请求地址：" + request.getRequestURL());
        ModelAndView mav = new ModelAndView();
        logger.error("异常信息：",e);
        mav.setViewName(errorView);
        return mav;
    }
}
